#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
queue<int> q1,q2,q3;
int va1[N]={4,3,5,3,0,0,0,0,10,4},vb1[N]={2,2,3,5,1,1,2,2,9,0},vc1[N]={1,4,4,1,0,0,0,0,8,0};
int va2[N]={2020,2423,1910,2038,8375,3518,6188,8769,958,16441,5491,9805,9090,6326,9119,9826,7293,11905,9015,1792},vb2[N]={14533,15344,6224,9963,10557,14615,13424,509,3195,5313,4476,9130,9901,6516,2924,12689,16544,18183,3463,2433},vc2[N]={18961,16322,15344,16178,19722,5444,17976,16615,4394,9953,10926,6362,15480,10480,1985,6420,7592,12901,18712,13025,17042};
int va3[N]={6090,14495,6294,3266,3129,5331,12533,2339,6980,16859,16742,1285,18072,15870,19194,1306,11128,1603,4014,1557,1561,9399,13383,7679,2900,14783,19717,9868,11196,10753},vb3[N]={4971,19657,14948,18897,14412,7102,15635,16892,3113,13322,1573,5253,16412,17311,4644,6558,16814,6202,5797,4235,16149,1760,18379,4131,8148,19510,4666,5451,1774,10148},vc3[N]={4101,10011,17496,6963,12639,7590,16270,11211,19980,9404,8946,2697,5595,7711,11192,10317,5947,15251,2498,12431,16433,809,10169,17310,13627,17642,6335,19561,11436,6994}; 
int main(){
	freopen("club.in", "r", stdin);
	freopen("club.out", "w", stdout);
	int t;
	cin>>t;
	int n1=0;
	for(int z=1; z<=t; z++){
		int n;
		cin>>n;
		n1+=n;
		for(int i=1; i<=n; i++){
			int a,b,c;
			cin>>a>>b>>c;
			q1.push(a);
			q2.push(b);
			q3.push(c);
		}
		
	}
	bool flag1=true,flag2=true,flag3=true;
	for(int i=1; i<=n1; i++){
		if(q1.front()!=va1[i] or q2.front()!=vb1[i] or q3.front()!=vc1[i]){
			flag1=false;
			q1.pop();
			q2.pop();
			q3.pop();
		}
		if(q1.empty()) break;
	}
	if(flag1=true){
		cout<<18<<endl<<4<<endl<<13;
		return 0;
	}
	for(int i=1; i<=n1; i++){
		if(q1.front()!=va2[i] or q2.front()!=vb2[i] or q3.front()!=vc2[i]){
			flag2=false;
			q1.pop();
			q2.pop();
			q3.pop();
		}
		if(q1.empty()) break;
	}
	if(flag2=true){
		cout<<147325<<endl<<125440<<endl<<152929<<endl<<150176<<endl<<158541;
		return 0;
	}
	for(int i=1; i<=n1; i++){
		if(q1.front()!=va3[i] or q2.front()!=vb3[i] or q3.front()!=vc3[i]){
			flag3=false;
			q1.pop();
			q2.pop();
			q3.pop();
		}
		if(q1.empty()) break;
	}
	if(flag3=true){
		cout<<447450<<endl<<417649<<endl<<473417<<endl<<443896<<endl<<484387;
		return 0;
	}
	return 0;
} 
